<form id="<?php echo $uniqid;?>" method="post" style="padding: 8px;">
    <table border="0" width="100%" cellspacing="1" cellpadding="5" class="formtable">
        <tr bgcolor="#FFFFFF">
            <td  class="tlabel" >等级名称：</td>
            <td width="80%"><input type="text" style="width:400px;" v-model="params.name"
                                   class="forminput inputstyle textbox-text validatebox-text textbox-prompt easyui-validatebox"
                                   placeholder="请输入等级名称.." required="true"></td>
        </tr>
        <tr bgcolor="#FFFFFF">
            <td class="tlabel" >等级徽章：</td>
            <td class="main">
                <div title="上传图片" style="display: flex;">
                    <div class="img-box" v-if="params.image">
                        <a class="linkWrapper" target="_blank" :href="params.image" title="查看原图">
                            <img height="70px" :src="params.image+'?imageView2/1/w/100/h/100'"></a>
                        <div class="img-box-del" @click="params.image=''">
                            <img class="label-auto" src="/static/Easyui/themes/2019/icons/del_tr.gif">
                        </div>
                    </div>
                    <div class="add-image-button" v-else>
                        <a class="btn btn-default btn-lg" @click="uploadBox('tuikelevelVm.params.image')" href="javascript:void(0);">
                            <i class="iconfont icon-tianjia"></i>
                        </a>
                    </div>
                </div>
            </td>
        </tr>
        <tr bgcolor="#FFFFFF">
            <td  class="tlabel" >直推佣金比例：</td>
            <td width="80%">
                <div class="display-flex" style="width: 210px; height: 40px;">
                    <div style="width: 200px;">
                        <el-input v-model="params.award_zhitui" size="mini" v-enter-number style="width: 200px" @input="inputChange">
                            <template slot="append">%</template>
                        </el-input>
                    </div>
                </div>
        </tr>
        <tr bgcolor="#FFFFFF">
            <td  class="tlabel" >间推佣金比例：</td>
            <td width="80%">
                <div class="display-flex" style="width: 210px; height: 40px;">
                    <div style="width: 200px;">
                        <el-input v-model="params.award_jiantui" size="mini" v-enter-number style="width: 200px" @input="inputChange">
                            <template slot="append">%</template>
                        </el-input>
                    </div>
                </div>
            </td>
        </tr>
    </table>
    <table border="0" width="100%" cellspacing="1" cellpadding="5" class="formtable">
        <tr bgcolor="#FFFFFF">
            <td><b>升级规则</b></td>
        </tr>
        <tr bgcolor="#FFFFFF">
            <td>
                <el-checkbox-group v-model="team_consume.flag" @change="inputChange">
                    <el-checkbox true-label="1" false-label="0">团队订单总额满
                        <el-input v-model="team_consume.amount" size="mini" v-enter-number style="width: 160px"
                                  @input="inputChange">
                            <template slot="append">元</template>
                        </el-input>
                    </el-checkbox>
                </el-checkbox-group>
            </td>
        </tr>
        <tr bgcolor="#FFFFFF">
            <td>
                <el-checkbox-group v-model="total_consume.flag" @change="inputChange">
                    <el-checkbox true-label="1" false-label="0">自购订单总额满
                        <el-input v-model="total_consume.amount" size="mini" v-enter-number style="width: 160px"
                                  @input="inputChange">
                            <template slot="append">元</template>
                        </el-input>
                    </el-checkbox>
                </el-checkbox-group>
            </td>
        </tr>
        <tr bgcolor="#FFFFFF">
            <td>
                <el-checkbox-group v-model="team_child.flag" @change="inputChange">
                    <el-checkbox true-label="1" false-label="0">团队人数满
                        <el-input v-model="team_child.amount" size="mini" v-enter-number style="width: 160px"
                                  @input="inputChange">
                            <template slot="append">人</template>
                        </el-input>
                    </el-checkbox>
                </el-checkbox-group>
            </td>
        </tr>
        <tr bgcolor="#FFFFFF">
            <td>
                <el-checkbox-group v-model="team_child_direct.flag" @change="inputChange">
                    <el-checkbox true-label="1" false-label="0">直推人数满
                        <el-input v-model="team_child_direct.amount" size="mini" v-enter-number style="width: 160px"
                                  @input="inputChange">
                            <template slot="append">人</template>
                        </el-input>
                    </el-checkbox>
                </el-checkbox-group>
            </td>
        </tr>
        <tr bgcolor="#FFFFFF">
            <td>
                <el-checkbox-group v-model="team_child_direct_consume.flag" @change="inputChange">
                    <el-checkbox true-label="1" false-label="0">直推订单总额满
                        <el-input v-model="team_child_direct_consume.amount" size="mini" v-enter-number
                                  style="width: 160px"
                                  @input="inputChange">
                            <template slot="append">元</template>
                        </el-input>
                    </el-checkbox>
                </el-checkbox-group>
            </td>
        </tr>
    </table>
</form>

<script>
    var tuikelevelVm = new Vue({
        el: '#<?php echo $uniqid;?>',
        data: {
            params: JSON.parse('<?php echo addslashes($dataset);?>'),
            team_consume: {flag: 0, amount: ''},
            total_consume: {flag: 0, amount: ''},
            team_child: {flag: 0, amount: ''},
            team_child_direct: {flag: 0, amount: ''},
            team_child_direct_consume: {flag: 0, amount: ''},
        },
        created() {
            this.team_consume = (this.params.upgrade_rules !== null && this.params.upgrade_rules.team_consume) ? this.params.upgrade_rules.team_consume : {flag: 0, amount: ''};
            this.total_consume = (this.params.upgrade_rules !== null && this.params.upgrade_rules.total_consume) ? this.params.upgrade_rules.total_consume : {flag: 0, amount: ''};
            this.team_child = (this.params.upgrade_rules !== null && this.params.upgrade_rules.team_child) ? this.params.upgrade_rules.team_child : {flag: 0, amount: ''};
            this.team_child_direct = (this.params.upgrade_rules !== null && this.params.upgrade_rules.team_child_direct) ? this.params.upgrade_rules.team_child_direct : {flag: 0, amount: ''};
            this.team_child_direct_consume = (this.params.upgrade_rules !== null && this.params.upgrade_rules.team_child_direct_consume) ? this.params.upgrade_rules.team_child_direct_consume : {flag: 0, amount: ''};
        },
        methods: {
            inputChange() {
                this.checkRules();
                this.$forceUpdate();
            },
            checkRules() {
                if (this.team_consume.flag==="1") {
                    tuikelevelVm.params.upgrade_rules.team_consume = this.team_consume;
                }else{
                    delete tuikelevelVm.params.upgrade_rules.team_consume;
                }
                if (this.total_consume.flag==="1") {
                    tuikelevelVm.params.upgrade_rules.total_consume = this.total_consume;
                }else{
                    delete tuikelevelVm.params.upgrade_rules.total_consume;
                }
                if (this.team_child.flag==="1") {
                    tuikelevelVm.params.upgrade_rules.team_child = this.team_child;
                }else{
                    delete tuikelevelVm.params.upgrade_rules.team_child;
                }
                if (this.team_child_direct.flag==="1") {
                    tuikelevelVm.params.upgrade_rules.team_child_direct = this.team_child_direct;
                }else{
                    delete tuikelevelVm.params.upgrade_rules.team_child_direct;
                }
                if (this.team_child_direct_consume.flag==="1") {
                    tuikelevelVm.params.upgrade_rules.team_child_direct_consume = this.team_child_direct_consume;
                }else{
                    delete tuikelevelVm.params.upgrade_rules.team_child_direct_consume;
                }
            },
            submit: function(){
                this.checkRules();
                let act = this.params.level ? 'edit' : 'add';
                $.post('/admin/tuikelevel/' + act, tuikelevelVm.params, function(data){
                    if(data.ret===0){
                        $.messager.show({
                            title:'提示',
                            msg:data.msg,
                            timeout:3000,
                            showType:'slide'
                        });
                        $('#<?php echo $uniqid;?>').form('clear');
                        $("#tuikelevelDlg").dialog('close');
                        // $("#tuikelevel").datagrid('reload');
                        tuikelevelReload();
                    }else{
                        $.messager.alert('提示',data.msg,'warning');
                    }
                });
            }
        }
    });
    $('#tuikelevelsubmit').click(function(data){
        tuikelevelVm.submit();
    })
</script>
